package com.zwy.com.zwy.activti;

import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngines;
import org.activiti.engine.TaskService;
import org.activiti.engine.task.Task;
import org.junit.Test;

import java.util.List;


/**
 * 处理当前任务
 * @author 天火
 * @className ActivitiTaskQuery
 */
public class ActivitiTaskComplete {

    /*public static void main(String[] arg){

        // 1.得到ProcessEngine对象
        ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
        //2.得到TaskService对象
        TaskService taskService = processEngine.getTaskService();
        //3.处理任务，结合用户查询当前的任务 5005
        taskService.complete("5005");
        //4.任务完成
        System.out.println("完成任务id：5005" );

    }*/
    public static void main(String[] arg){

        // 1.得到ProcessEngine对象
        ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
        //2.得到TaskService对象
        TaskService taskService = processEngine.getTaskService();
        //3.处理任务，结合用户查询当前的任务 5005
        taskService.complete("7502");
        //4.任务完成
        System.out.println("完成任务id：5005" );

    }

    @Test
    public void queryAndComplete(){
        // 1.得到ProcessEngine对象
        ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
        //2.得到TaskService对象
        TaskService taskService = processEngine.getTaskService();
        //3.处理任务，结合用户查询当前的任务 5005
        Task task = taskService.createTaskQuery()
                .processDefinitionKey("holiday")
                .taskAssignee("王五")
                .singleResult();

        taskService.complete(task.getId());
        //4.任务完成
        System.out.println("完成任务id：5005" );
    }
}
